package com.wl.index.Biz.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wl.entity.ChilderComments;
import com.wl.index.Biz.IChilderCommentsBiz;
import com.wl.index.Mapper.ChilderCommentsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ChilderCommentsBizImpl extends ServiceImpl<ChilderCommentsMapper, ChilderComments> implements IChilderCommentsBiz {

    @Autowired
    private ChilderCommentsMapper ccMapper;

    @Override
    public List<ChilderComments> getChilderCommentsByCid(Integer cid, Integer nid) {
        List<ChilderComments> ccoments = ccMapper.getChilderCommentsByCid(cid, nid);
        return ccoments;
    }

    @Override
    public List<Map<String, Object>> getCCommentsByUid(Integer cid, Integer nid) {
        List<Map<String, Object>> ccoments = ccMapper.getCCommentsByUid(cid, nid);
        return ccoments;
    }

    @Override
    public int addChilderComments(@RequestBody ChilderComments ccomments) {
        if (ccomments == null || ccomments.getCid() == null){
            throw new IllegalArgumentException("缺少必要参数");
        }
        // 如果creatAt为null，设置为当前时间
        if(ccomments.getCreatAt() == null) {
            ccomments.setCreatAt(new Date());
        }
        return ccMapper.addChilderComments(ccomments);
    }
}
